<template>
	<div class="container" @tap="preview">
		<view class="flex-between">
			<view class="df ac flex-1">
				<image
					src="@/static/img/attachment.png"
					style="width: 40rpx; height: 40rpx"
				></image>
				<view class="ml20">
					<view class="filename-color">{{
						getNameByCenterDot(value.fileName)
					}}</view>
					<view class="f26 c6">{{
						formatSizeUnits(value.fileSize)
					}}</view>
				</view>
			</view>
			<!-- {{ $store.state.instanceProgress.length }} -->
			<view
				v-if="
					(activeTasks && activeTasks.length > 0) ||
					(auditTasks && auditTasks.length > 0)
				"
			>
				<view
					v-if="
						$store.state.readFileList &&
						$store.state.readFileList.length
							? $store.state.readFileList.some(
									(i) => i.paramId == value.paramId
							  )
							: false
					"
					class="is-read f26 pd"
					>已读</view
				>
				<view v-else class="is-noRead f26 pd">未读</view>
			</view>
		</view>
		<view class="f26 g6 mt20">文件类别</view>
		<view class="c10">{{ value.fileConfigs.fileType }}</view>
	</div>
</template>

<script>
import { formatSizeUnits, getNameByCenterDot } from '@/common/utils.js'
export default {
	props: {
		value: {
			type: Object,
			default: () => {
				return {}
			},
		},
	},
	data() {
		return {
			formatSizeUnits,
			getNameByCenterDot,
			loginUser: uni.getStorageSync('userId'),
		}
	},
	mounted() {},
	computed: {
		// 审批人判断视角
		activeTasks() {
			return this.judgeActiveTask(this.$store.state.instanceProgress)
		},
		//办理人审批视角
		auditTasks() {
			return this.judgeAuditTasks(this.$store.state.instanceProgress)
		},
	},
	methods: {
		preview() {
			this.$request
				.request('wflow/wflow/process/variable/getSealShowFileUrl', {
					method: 'get',
					data: {
						fileId: this.value.paramId,
						instanceId: uni.getStorageSync('instanceId'),
					},
				})
				.then((res) => {
					if (res.success) {
						const params = {
							Authorization: uni.getStorageSync('token'),
							userId: uni.getStorageSync('userId'),
							cookie: 'sessionType=APP;timeout=-1;point=uni_app',
							tenantId: uni.getStorageSync('orgId'),
							'content-type': 'application/json',
							reqChannel: 100013,
							paramId: this.value.paramId,
							instanceId: uni.getStorageSync('instanceId'),
							pdfurl: res.data,
						}
						uni.navigateTo({
							url: `/subPackagesIndex/pages/index/webViewUrl/index?url=https://mobile-dev.yilife.cn/pdf&Authorization=${params.Authorization}&userId=${params.userId}&tenantId=${params.tenantId}&paramId=${params.paramId}&instanceId=${params.instanceId}&pdfurl=${params.pdfurl}`,
						})
					}
				})
		},
		//判断审批人视角
		judgeActiveTask(list) {
			let tasks = []
			;(list || []).forEach((task) => {
				if (task.users) {
					task.users.forEach((tk) => {
						if (tk.user.id == this.loginUser && !tk.finishTime) {
							tasks.push(tk)
						}
					})
				} else {
					if (task.user.id == this.loginUser && !task.finishTime) {
						tasks.push(task)
					}
				}
			})
			return tasks
		},

		// 判断办理人视角
		judgeAuditTasks(list) {
			let tasks = []
			;(list || []).forEach((task) => {
				if (task.users) {
					task.users.forEach((tk) => {
						if (
							tk.user.id == this.loginUser &&
							tk.nodeType == 'AUDIT' &&
							!tk.finishTime
						) {
							tasks.push(tk)
						}
					})
				} else {
					if (
						task.user.id == this.loginUser &&
						task.nodeType == 'AUDIT' &&
						!task.finishTime
					) {
						tasks.push(task)
					}
				}
			})
			return tasks
		},
	},
	watch: {},
}
</script>

<style lang="scss" scoped>
.container {
	border-radius: 8rpx;
	background-color: rgba(58, 155, 255, 0.08);
	margin-bottom: 10rpx;
}
.filename-color {
	color: #3a74fc;
}
.is-noRead {
	border-radius: 4px;
	background-color: rgba(255, 241, 240, 1);
	color: rgba(222, 134, 143, 1);
	border: #ffa39e;
}
.pd {
	padding: 5rpx 10rpx;
}
.is-read {
	border-radius: 4px;
	background-color: rgba(246, 255, 237, 1);
	color: rgba(129, 179, 55, 1);
	border: #b7eb8f;
}
</style>
